package com.googlecode.dgwt.client.dojox.data.model;

import com.googlecode.dgwt.client.dojo.data.format.ValueFormatter;
import com.googlecode.dgwt.client.dojox.data.model.base.DataColumnBase;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public abstract class DataColumn<Item, Type> extends DataColumnBase<Item, Type> {

    private Class<? extends Type> columnType;

    public DataColumn(Class<? extends Type> columnType) {
        super();
        setColumnType(columnType);
    }

    public DataColumn(Class<? extends Type> columnType, String title) {
        super(title);
        setColumnType(columnType);
    }

    public DataColumn(Class<? extends Type> columnType, String title, int maxLength) {
        super(title, maxLength);
        setColumnType(columnType);
    }

    public DataColumn(Class<? extends Type> columnType, String title, String width) {
        super(title, width);
        setColumnType(columnType);
    }

    public DataColumn(Class<? extends Type> columnType, String title, String width, ValueFormatter<Type> formatter) {
        super(title, width);
        setColumnType(columnType);
        setFormatter(formatter);
    }

    public DataColumn(Class<? extends Type> columnType, String title, int maxLength, ValueFormatter<Type> formatter) {
        super(title, maxLength);
        setColumnType(columnType);
        setFormatter(formatter);
    }
    
    @Override
    public Class<? extends Type> getColumnType() {
        return columnType;
    }

    @SuppressWarnings("unchecked")
    public void setColumnType(Class<? extends Type> classType) {
        if (classType == null){
            classType = (Class) Object.class;
        }
        this.columnType = classType;
        updateFormatter();
    }

}
